package com.bdbit.ChargingStation.entity;

public class returnBean<T> {
    private int code;
    private String message;
    private T data;  // 使用泛型替代特定类型

    public returnBean() {
        this.code = 0;
        this.message = "";
    }

    // 快速创建成功响应
    public static <T> returnBean<T> success(T data) {
        returnBean<T> rb = new returnBean<>();
        rb.setCode(200);
        rb.setMessage("success");
        rb.setData(data);
        return rb;
    }

    // 快速创建错误响应（支持泛型推断）
    public static <T> returnBean<T> error(int code, String message) {
        returnBean<T> rb = new returnBean<>();
        rb.setCode(code);
        rb.setMessage(message);
        return rb;
    }

    // 快速创建错误响应（无数据，避免类型推断问题）
    public static returnBean<Void> error(int code, String message, Class<Void> type) {
        returnBean<Void> rb = new returnBean<>();
        rb.setCode(code);
        rb.setMessage(message);
        return rb;
    }

    // Getter 和 Setter
    public int getCode() { return code; }
    public void setCode(int code) { this.code = code; }

    public String getMessage() { return message; }
    public void setMessage(String message) { this.message = message; }

    public T getData() { return data; }
    public void setData(T data) { this.data = data; }
}